# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        潘炎珍  
# Name:         db_manage
# Description:
# Author:       98745
# Date:         2019/4/9
#-------------------------------------------------------------------------------

from pymysql import *

def connectdb():
    db=connect("127.0.0.1","root","root","xuexi",charset='utf8')
    return db

db=connectdb()

def create(db):
    cursor=db.cursor()
    sql='''
    create table zhaopin 
    (职位名称 varchar(30),工资 varchar(20),工作地点 varchar(20),经验要求 varchar(20),学历 varchar(20),公司名称 varchar(30),公司概况 varchar(30));'''
    try:
        cursor.execute(sql)
        db.commit()
        return True
    except Exception as e:
        print(e)
        db.rollback()


def insert(db,data):
    try:
        cursor=db.cursor()
        sql="insert into zhaopin values('{}','{}','{}','{}','{}','{}','{}')".format(data['position'],data['salary'],data['place'],data['experience'],data['education'],data['company'],data['character'])
        cursor.execute(sql)
        db.commit()
        return True
    except Exception as e:
        print(e)
        db.rollback()
    return False


if __name__ == '__main__':
    print(create(db))